package mww.javabean.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import mww.common.DaoException;
import mww.javabean.dao.CourseDaoImpl;
import mww.javabean.dao.CourseDao;

import mww.common.ServiceException;
import mww.javabean.entity.Course;

public class CourseServiceImpl implements CourseService {

	private CourseDao courseDao = new CourseDaoImpl();

	// 添加课程方法
	@Override
	public void addCourse(Course course) throws ServiceException {
		try {
			courseDao.addCourse(course);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	// 删除课程方法
	@Override
	public void delCourse(String courseNo) throws ServiceException {
		try {
			courseDao.delCourse(courseNo);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	// 修改课程信息
	@Override
	public void updateCourse(Course course) throws ServiceException {
		try {
			courseDao.updateCourse(course);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
	}

	// 根据课程编号查找课程
	@Override
	public Course findCourseByCourseNo(String courseNo) throws ServiceException {
		Course course = null;
		try {
			course = courseDao.findCourseByCourseNo(courseNo);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return course;
	}

	// 列表显示所有课程列表--分页
	@Override
	public Map findAllCourse(int curPage) throws ServiceException {
		Map map = null;
		try {
			map = courseDao.findAllCourse(curPage);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return map;
	}

	// 列表显示所有课程列表
	@Override
	public List findAllCourse() throws ServiceException {
		List list = new ArrayList();
		try {
			list = courseDao.findAllCourse();
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return list;
	}

	// 多条件查询课程
	@Override
	public List findAllCourseByMostCon(Course condition) throws ServiceException {
		List list = null;
		try {
			list = courseDao.findAllCourseByMostCon(condition);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return list;
	}

	// 多条件查询课程--带分页
	@Override
	public Map findAllCourseByMostCon(Course condition, int curPage) throws ServiceException {
		Map map = null;
		try {
			map = courseDao.findAllCourseByMostCon(condition, curPage);
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return map;
	}

	@Override
	public int getTeacherTotality() throws ServiceException {
		int number = 0;
		try {
			number = courseDao.findAllCourse().size();
		} catch (DaoException e) {
			e.printStackTrace();
			throw new DaoException(e.getMessage(), e);
		}
		return number;
	}

}
